<?php $this->load->view(TEMPLATE_NAME.'/admin/header');?>

<?php $this->load->view(TEMPLATE_NAME.'/admin/side_left');?>

<link rel="stylesheet" type="text/css" media="all" href="<?php echo base_url()?>xhtml/admin/css/tia.css" />

<script type="text/javascript" src="<?php echo base_url()?>js/jquery-1.4.2.js"></script>

<script type="text/javascript" src="<?php echo base_url()?>js/jquery.validate.pack.js"></script>

<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>

<script src="<?php echo base_url(); ?>js/jquery.NobleCount.min.js"></script>

<script src="<?php echo base_url(); ?>js/ajaxfileupload.js"></script>

<script src="<?php echo base_url(); ?>js/si.files.js"></script>

<style type="text/css" title="text/css">

.SI-FILES-STYLIZED label.cabinet

{

    width: 100px;

    height: 28px;

    background: url('<?php echo base_url()?>image/select_image.jpg') 0 0 no-repeat;



    display: block;

    overflow: hidden;

    cursor: pointer;

}



.SI-FILES-STYLIZED label.cabinet input.file

{

    position: relative;

    height: 100%;

    width: auto;

    opacity: 0;

    -moz-opacity: 0;

    filter:progid:DXImageTransform.Microsoft.Alpha(opacity=0);

}

#info p{

    color: red;

}

/* Style for jquery validation */

#company_form label.error {    

    background-color: #cccc00;    

    color: #000;    

    padding: 5px 10px;    

    width: 320px;    

    margin: 0 0 0 0px;    

    float: none;    

    height:19px;    

    line-height:19px;

    position:relative;

    display:block;

    font-weight: normal;

}

</style>

<script type="text/javascript">

SI.Files.stylizeAll();

  $(document).ready(function(){

    var result = true;    

    $.validator.addMethod("companyCheck", function() {                                                

        $.post("<?php echo site_url('json_request/check_company_json')?>" ,{

            company: $('#name').val(),

            existing: '<?php echo $company['company_slug_name'];?>'                                  

        },function(data){            

            result = (data=="TRUE") ? true : false;

        }, "json");

            return result;            

    });



    $("#company_form").validate({                

        onkeyup: false,                

        rules: {            

            name: {

                required : true,

                companyCheck : true    

            },

            description : "required",

            contact_number : "required",

            province_name : "required",

            city_name : "required",

            physical_street : "required",

            physical_suburb : "required",

            contact_email : "email",
            
            physical_city : "required"

        },        

        messages: {            

            name: {

                required : "Please input a Company Name",

                companyCheck : "Duplicate Company name exists in directory"    

            },            

            description : "Please input a Company Description",

            contact_number : "Please input a Telephone Number for customers",

            province_name : "Please select a Province/Region",

            city_name : "Please input a City or Town",

            physical_street : "Please input a Street Address",

            physical_suburb : "Please input a Suburb",
            
            contact_email : "Please input a valid Email Address",
                
            physical_city : "Please input a City or Town"

        }          

    });

$('#text_detail').NobleCount('#count_detail',{

    max_chars: 1000,

    block_negative: true

});



    // initialization on onload

    var map;

    var marker;

    initialize();

    $('#sys_address').change(function(){

      codeAddress();

    });

    $('#sys_suburb').change(function(){

      codeAddress();

    });

        

    $('#sys_city').change(function(){

      codeAddress();

    });

    

    $('#sys_search').click(function(){

      codeAddress();

    });

        $('#add_link').click(function(){

            $('#more_link').append('<input type="text" value="" name="link[]"/>');

            return false;

        });

        

    $('#hour').bind('change',function(){

      $('input[name="incident_time"]')[0].checked = true; 



   });

   $('#minute').bind('change',function(){

     $('input[name="incident_time"]')[0].checked = true; 

   });

/* checkbox physical address click*/

        $('#addressabove').click(function(){

            if ($(this).is(':checked')){

                $('#postal_street').val($('#sys_address').val());

                $('#postal_suburb').val($('#sys_suburb').val());

                $('#postal_city').val($('#sys_city').val());

                $('#postal_zipcode').val($('#sys_zipcode').val());

            }

        });

  });    

  function initialize() {    

    geocoder = new google.maps.Geocoder();

<?php if(!empty($company['latitude']) && !empty($company['longitude'])){ 

    ?>

    

    var myLatlng = new google.maps.LatLng(<?php echo $company['latitude'] ?>, <?php echo $company['longitude'] ?>);

      $('#sys_lat').val('<?php echo $company['latitude'] ?>');

      $('#sys_lng').val('<?php echo $company['longitude'] ?>');

<?php }else{ ?>



    var myLatlng = new google.maps.LatLng(-33.92526381, 18.420553054565435);

      $('#sys_lat').val('-33.92526381');

      $('#sys_lng').val('18.420553054565435');

<?php } ?>

    var myOptions = {

      zoom: 13,

      center: myLatlng,

      mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},

      mapTypeId: google.maps.MapTypeId.ROADMAP

    }

    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

   var image = new google.maps.MarkerImage('<?php echo base_url(); ?>image/point/pin_point.png',

      // This marker is 20 pixels wide by 32 pixels tall.

      new google.maps.Size(24, 35),

      // The origin for this image is 0,0.

      new google.maps.Point(0,0),

      // The anchor for this image is the base of the flagpole at 0,32.

      new google.maps.Point(0, 32));

  var shadow = new google.maps.MarkerImage('<?php echo base_url(); ?>image/point/pin_point_shadow.png',

      // The shadow image is larger in the horizontal dimension

      // while the position and offset are the same as for the main image.

      new google.maps.Size(49, 35),

      new google.maps.Point(0,0),

      new google.maps.Point(10, 35)); 

    marker = new google.maps.Marker({

        position: myLatlng, 

        map: map,

    draggable: true,

    title:"Incident Location",

    icon: '<?php echo base_url(); ?>image/point/pin_point.png',

    shadow: shadow  

    });   

      $('#sys_latlng').val(myLatlng);

    // Add dragging event listeners.

    google.maps.event.addListener(marker, 'dragend', function() {

      $('#sys_latlng').val(marker.getPosition());

      $('#sys_lat').val(marker.getPosition().lat());

      $('#sys_lng').val(marker.getPosition().lng());

    });





  }

    function codeAddress() {

      var street_address = document.getElementById("sys_address").value;

      var suburb_address = document.getElementById("sys_suburb").value;

      var city_address = document.getElementById("sys_city").value;

      var address = street_address+', '+suburb_address+', '+city_address;

      if (geocoder) {

    geocoder.geocode( { 'address': address}, function(results, status) {

      if (status == google.maps.GeocoderStatus.OK) {

        map.setCenter(results[0].geometry.location);

        marker.setPosition(results[0].geometry.location);

        $('#sys_latlng').val(marker.getPosition());

        $('#sys_lat').val(marker.getPosition().lat());

        $('#sys_lng').val(marker.getPosition().lng());

      } else {

        //alert("Geocode was not successful for the following reason: " + status);

      }

    });

      }

    }

// function upload jquery

function ajaxFileUpload(){

    $("#loading")

    .ajaxStart(function(){

        $(this).show();

    })

    .ajaxComplete(function(){

        $(this).hide();

    });



    $.ajaxFileUpload({

        url:'<?php echo site_url('ajax_upload/upload_directory_image/upload/company/network')?>/<?php echo $company_detail['company']?>',

        secureuri:false,

        fileElementId:'fileToUpload',

        dataType: 'json',

        success: function (data, status){

            if(typeof(data.error) != 'undefined')

            {

                if(data.error != ''){

                    $("#info").html('<img src="<?php echo base_url()?>xhtml/img/forlogo2.gif" width="150" height="150">'+data.error);

                }else{                        

                    $("#info").html('<img src="<?php echo base_url();?>uploads/directory/company_logo/thumb/'+data.msg

                    +'" width="150" />'

                    +'<input type="hidden" name="upload" value="'+data.msg +'">');

                }

            }

        },

        error: function (data, status, e){

            $("#info").html(e);

        }

    })        

    return false;

}

</script>

<div class="page noright adminpage">

<h5 class="purple">The Mykprisguide Print - Design Directory</h5>

<hr />

<?php $this->load->view(TEMPLATE_NAME.'/admin/directory/directory_admin_header');?>

<hr />

<?php $this->load->view(TEMPLATE_NAME.'/admin/directory/directory_admin_editlisting_header');?> 

<hr />

<?php if(!empty($notification)){ ?>

<p class="inform f12 error_message"><?php echo $notification ?></p>

<?php } ?>

<div class="wright">

<?php

$action = 'admin/design_directory/company_detail/id/'.$company['id']; 

$attributes = array('class' => 'dirad', 'id' => 'company_form');

echo form_open_multipart($action, $attributes);?>

<div class="box company_dtl_box">

<div class="bleft">

<h4>Company Details</h4>

<p class="purple1"><b>Input your company details here to DISPLAY on your advert in the directory.</b></p>

<p>You have <strong id="count_detail" class="purple1">1000</strong> characters left</p>

</div><!-- bleft -->

<div class="bright">

<label>Company Name: <span>(Required)</span></label><br />

<?php 

$input_company = array('name' => 'name','id' => 'name', 'value' => $company['company']);

echo form_input($input_company);//form_input('name',$company['company']); ?>

<?php echo form_error('name','<p id="error_recaptcha" class="inform f12 error_message"><strong>Error:</strong>','</p>') ?>

<br />

<label>Company description: <span>(Required)</span></label><br />

<?php echo form_textarea(array('name'=>'description','id'=>'text_detail'),$company['company_description']); ?>

<?php echo form_error('description','<p id="error_recaptcha" class="inform f12 error_message"><strong>Error:</strong>','</p>') ?>

<br />

<label>Telephone Number: <span>(Required)</span></label><br />

<?php echo form_input('contact_number',$company['company_contact_number']); ?>

<?php echo form_error('contact_number','<p id="error_recaptcha" class="inform f12 error_message"><strong>Error:</strong>','</p>') ?>

<br />

<label>Fax Number:  <span>(Optional)</span></label><br />

<?php echo form_input('fax_number',$company['fax_number']); ?>

<?php echo form_error('fax_number','<p id="error_recaptcha" class="inform f12 error_message"><strong>Error:</strong>','</p>') ?>

<br />

<label>Email:  <span>(Optional)</span></label><br />

<?php echo form_input('contact_email',$company['company_contact_email']); ?>

<?php echo form_error('contact_email','<p id="error_recaptcha" class="inform f12 error_message"><strong>Error:</strong>','</p>') ?>

<br />

<label>Website: <span>(Optional)</span></label><br />

<?php 

if(empty($company['company_website'])){

    $website = 'http://';    

}else{

    $website = 'http://'.$company['company_website'];

}

echo form_input('website',$website); ?>

<?php echo form_error('website','<p id="error_recaptcha" class="inform f12 error_message"><strong>Error:</strong>','</p>') ?>

<br />

</div><!-- bright -->

<div class="clear"></div>

</div><!-- box -->

<div class="boxe f15">

<p><b>NO SPAM!
Your e-mail address/es are NEVER displayed openly - this means you will not get spam from your listing.</b></p>

<div class="clear"></div>

</div><!-- boxe -->

<div class="box">

<div class="bleft">

<h4>Location info</h4>
<p><b class="purple1">Geographical location for fast directory filtering.</b></p>

</div><!-- bleft -->

<div class="bright">

<label>Province/Region: <span>(Required)</span></label><br />

<select name="province_id">

<option value="">Select Province/Region</option>

<?php /*$company_detail['province_name'] = trim($company_detail['province_name']);?>

<option value="Gauteng" <?php if($company_detail['province_name'] == 'Gauteng'){?> selected="selected" <?php }?> >Gauteng</option>

<option value="KwaZulu Natal" <?php if($company_detail['province_name'] == 'KwaZulu Natal'){?> selected="selected" <?php }?> >KwaZulu Natal</option>

<option value="Western Cape" <?php if($company_detail['province_name'] == 'Western Cape'){?> selected="selected" <?php }?> >Western Cape</option>

<option value="Eastern Cape" <?php if($company_detail['province_name'] == 'Eastern Cape'){?> selected="selected" <?php }?> >Eastern Cape</option>

<option value="Free State" <?php if($company_detail['province_name'] == 'Free State'){?> selected="selected" <?php }?> >Free State</option>

<option value="Limpopo" <?php if($company_detail['province_name'] == 'Limpopo'){?> selected="selected" <?php }?> >Limpopo</option>

<option value="Mpumalanga" <?php if($company_detail['province_name'] == 'Mpumalanga'){?> selected="selected" <?php }?> >Mpumalanga</option>

<option value="North West" <?php if($company_detail['province_name'] == 'North West'){?> selected="selected" <?php }?> >North-West</option>

<option value="Northern Cape" <?php if($company_detail['province_name'] == 'Northern Cape'){?> selected="selected" <?php }?> >Northern Cape</option>

<option value="Outside South Africa" <?php if($company_detail['province_name'] == 'Outside South Africa'){?> selected="selected" <?php }?> >Outside South Africa</option>

*/?>

<?php if(!empty($region_list)): ?>

<?php foreach($region_list as $key=>$value): ?>

<option value="<?php echo $value['id']?>" <?php if($company['region_id'] == $value['id']){?> selected="selected" <?php }?>><?php echo $value['name'] ?></option>

<?php endforeach;?>

<?php endif; ?>

</select>

<?php echo form_error('province_id','<p id="error_recaptcha" class="inform f12 error_message"><strong>Error:</strong>','</p>') ?><br>

<label>City / Town: <span>(Required)</span></label><br>

<!--<input type="text" value="Input example">-->

<?php echo form_input(array('name'=>'city_name'),$company['city_name']); ?>

<?php echo form_error('city_name','<p id="error_recaptcha" class="inform f12 error_message"><strong>Error:</strong>','</p>') ?><br />

</div><!-- bright -->

<div class="clear"></div>

</div><!-- box -->

<div class="box">

<div class="bleft">

<h4>Physical Address</h4>

<p><b class="purple1">Input your physical company address.</b></p>

</div><!-- bleft -->

<div class="bright">

<label>Street Address: <span>(Required)</span></label><br />

<?php echo form_input(array('name'=>'physical_street','id'=>'sys_address'),$company['physical_street']); ?>

<?php echo form_error('physical_street','<p id="error_recaptcha" class="inform f12 error_message"><strong>Error:</strong>','</p>') ?>

<br />

<label>Suburb: <span>(Required)</span></label><br />

<?php echo form_input(array('name'=>'physical_suburb','id'=>'sys_suburb'),$company['physical_suburb']); ?>

<?php echo form_error('physical_suburb','<p id="error_recaptcha" class="inform f12 error_message"><strong>Error:</strong>','</p>') ?>

<br />

<label>City / Town: <span>(Required)</span></label><br />

<?php echo form_input(array('name'=>'physical_city','id'=>'sys_city'),$company['physical_city']); ?>

<?php echo form_error('physical_city','<p id="error_recaptcha" class="inform f12 error_message"><strong>Error:</strong>','</p>') ?>

<br />

<label>Postal Code: <span>(Optional)</span></label><br />

<?php echo form_input(array('name'=>'physical_zipcode','id'=>'sys_zipcode'),$company['physical_zipcode']); ?>

<?php echo form_error('physical_zipcode','<p id="error_recaptcha" class="inform f12 error_message"><strong>Error:</strong>','</p>') ?>

<br />

</div><!-- bright -->

<div class="clear"></div>

</div><!-- box -->

<div class="box">

<div class="bleft">

<h4>Company Map</h4>

<p><b class="purple1">Input your company address above and them check the pin location of your company on the map - if it's wrong then  check your address above, ensuring correct spelling capilatisation for names and then click the "fix incorrect marker location" to correct it below.</b></p>

<!--<p class="f14"><a href="#"><strong>&gt; Fix incorrect marker location</strong></a></p>-->

</div><!-- bleft -->

<div class="bright">

<div id="map_canvas" style="width:300px;height:301px"></div>

<input type="hidden" name="latitude" id="sys_lat" />

<input type="hidden" name="longitude" id="sys_lng" />

</div><!-- bright -->

<div class="clear"></div>

</div><!-- box -->

<!-- box -->

<div class="box">

<div class="bleft">

<h4>Company Logo</h4>

<p class="purple1"><strong class="purple1">(OPTIONAL) <br />

Upload your company logo to display on your advert.</strong></p>

<!--<a class="file" href="#">Select File</a>-->

<!-- ie show button -->

<?php if (isset($_SERVER['HTTP_USER_AGENT']) && (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false)):?>

      <input type="file" class="file" id="fileToUpload" name="fileToUpload" onchange="return ajaxFileUpload();" />

 <?php else:  ?>

    <label class="cabinet"> 

        <input type="file" class="file" id="fileToUpload" name="fileToUpload" onchange="return ajaxFileUpload();" />

    </label>

<?php endif;?>

</div><!-- bleft -->

<div class="bright" style="position:relative">

    <img id="loading" src="<?php echo base_url()?>image/loading_blue.gif" style="display:none;position:absolute;z-index:1000;left:65px;top:60px" />   

    <div id="info">

        <?php if(!empty($company['company_logo'])){?>

            <img src="<?php echo base_url()?>uploads/directory/company_logo/thumb/<?php echo $company['company_logo']?>" width="150"  height="150">

            <input type="hidden" name="upload" value="<?php echo $company['company_logo']?>">

        <?php } else{?>

            <img src="<?php echo base_url()?>xhtml/img/forlogo2.gif" width="150" height="150">        

        <?php } ?>

   <div style="padding-bottom:15px;"><b class="purple1">Upload a logo file in RGB JPG format only.</b></div>

<div style="padding-bottom:15px;"><b class="purple1">To replace exsiting logo, simply select and upload another image.</b></div>

<div style="padding-bottom:15px;"><b class="purple1">Click <u><a style="cursor:pointer" onclick="clear_logo();">clear logo</a></u> to remove the logo uploaded here.</span></b></div>

 </div>

</div><!-- bright -->

<div class="clear"></div>

</div><!-- box -->

<div class="">

<div class="line"></div>
<div class="">

<?php 

$form_button = array(

  'type'=>'submit',

  'name'=>'submit',

  'value'=>'submit',

  'content'=>'Submit',

);

echo form_button($form_button) ?>

</div><!-- bright -->

<div class="clear"></div>

</div><!-- box -->

<?php echo form_close(); ?>

</div><!-- wright -->

</div><!-- page -->

<?php $this->load->view(TEMPLATE_NAME.'/admin/footer');?>